package com.yc.fav.servlet;

import com.google.gson.Gson;
import com.yc.fav.vo.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/10/28
 * Email haijunzhou@hnit.edu.cn
 */
@WebServlet("/myinfo")
public class myinfoServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        Object myinfo = req.getSession().getAttribute("myinfo");
        Result ret;
        if(myinfo == null){
            ret = new Result(0, "未登录", null);
        } else {
            ret = new Result(1, "已登录", myinfo);
        }
        String json = new Gson().toJson(ret);
        resp.getWriter().append(json);
    }
}

